export default {
  namespaced:true,
  state:{
    attr:{
      width:375,
      height:667,
    },
    index:0,
    newList:{}, //当前移动参数
    content:[],
    ghostClass:"" //设置拖动元素的占位符类名
  },
  mutations:{
    saveNewList(state,value){
      state.newList = value
    },
    saveContent(state,res){
      let content = JSON.parse(JSON.stringify(state.content))
      let oldIndex = res.oldIndex
      let newIndex = res.newIndex
      let newContent = state.content[newIndex]
      if(oldIndex != undefined){ // 替换模式
        let oldContent = state.content[oldIndex]
        content[newIndex] = oldContent
        content[oldIndex] = newContent
      }else{ // 新增模式
        if(newIndex <= state.index){
          console.log(newIndex,state.index)
          for(let i in content){
            console.log(i,content)
            if(content[i].index >= newIndex){
              let o = parseInt(i) + 1
              // content[i].index++
              content[o] = content[i]
            }
          }
          res.element.index = state.index
          content[newIndex] = res.element
        }else{
          res.element.index = state.index
          content.push(res.element)
        }
        state.index++
      }
      state.content = content
      console.log("saveContent",state.content)
    },
    setGhostClass(state,value){
      console.log(value)
      state.ghostClass = value
    }
  },
  actions:{

  }
}